import pymysql

class Emp():
    def __init__(self,empno,ename,job,mgr,hiredate,sal,comm,deptno):
        self.empno = empno
        self.ename = ename
        self.job = job
        self.mgr = mgr
        self.hiredate = hiredate
        self.sal = sal
        self.comm = comm
        self.deptno = deptno

    def __str__(self):
        return f'{self.empno}\t{self.ename}\t{self.job}\t{self.mgr}\t{self.hiredate}\t{self.sal}\t{self.comm}\t{self.comm}\t{self.deptno}'
def main():
    conn = pymysql.connect(host='',port=3306,
                           user='root',password='admin@9000',
                           database='my_database',charset='utf8',
                           cursorclass=pymysql.cursors.DictCursor)
    try:
        with conn.cursor() as cursor:
            cursor.execute("select empno,ename,job,mgr,hiredate,sal,comm,deptno from TB_EMP;")
            for row in cursor.fetchall():
                emp = Emp(**row)
                print(emp)
    except pymysql.MySQLError as error:
        print(error)
    finally:
        conn.close()
    print(conn)
if __name__ == '__main__':
    main()
